/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.yournamehere.client;

import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.types.TreeModelType;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.tab.TabSet;
import com.smartgwt.client.widgets.tree.*;
import com.smartgwt.client.widgets.tree.events.LeafClickEvent;
import com.smartgwt.client.widgets.tree.events.LeafClickHandler;

public class MenuPrincipal{


    public static final TreeNode[] employeeData = new TreeNode[] {
        new EmployeeTreeNode("01", "1", "Asistencias"),
        new EmployeeTreeNode("02", "2", "Evaluaciones"),
        new EmployeeTreeNode("03", "3", "Avanze Curricular"),
        new EmployeeTreeNode("04", "3", "Proceso de Matriculas"),
            new EmployeeTreeNode("41", "04", "Matricularse"),
            new EmployeeTreeNode("42", "04", "Constancia de Matricula"),
        new EmployeeTreeNode("05", "5", "Consolidado de Notas")
    };


    TreeGrid employeeTreeGrid;
    TabSet Panel;
    private static MenuPrincipal INSTANCE = null;
    static HLayout Principal;

    static public HLayout getLayout()
    {
        if(INSTANCE==null)
            INSTANCE=new MenuPrincipal();
        return Principal;
    }

    private MenuPrincipal()
    {
        Principal=new HLayout();
        init();
        employeeTreeGrid.setContents("Navigation");
        employeeTreeGrid.setAlign(Alignment.CENTER);
        employeeTreeGrid.setOverflow(Overflow.HIDDEN);
        employeeTreeGrid.setWidth("100%");
        employeeTreeGrid.setHeight("100%");
        employeeTreeGrid.setShowResizeBar(true);
        
    }


    public void init() {
        Tree employeeTree = new Tree();
        employeeTree.setModelType(TreeModelType.PARENT);
        employeeTree.setIdField("antID");
        employeeTree.setParentIdField("ID");
        employeeTree.setNameProperty("Name");
        employeeTree.setRootValue(1);
        employeeTree.setData(employeeData);

        TreeGridField field = new TreeGridField("Name", "Alumno");
        field.setCanSort(false);
        
        employeeTreeGrid = new TreeGrid();
        employeeTreeGrid.setWidth("100%");
        employeeTreeGrid.setHeight("100%");
        employeeTreeGrid.setNodeIcon(null);
        employeeTreeGrid.setFolderIcon(null);
        employeeTreeGrid.setShowOpenIcons(false);
        employeeTreeGrid.setShowDropIcons(false);
        employeeTreeGrid.setClosedIconSuffix("");
        employeeTreeGrid.setFields(new TreeGridField("Name"));
        employeeTreeGrid.setData(employeeTree);
        employeeTreeGrid.setFields(field);
        employeeTreeGrid.addLeafClickHandler(new LeafClickHandler(){
            public void onLeafClick(LeafClickEvent event) {
                int cod=Integer.parseInt(event.getLeaf().getAttribute("antID"));
                 //SC.say(event.getLeaf().getAttribute("antID"));
                 switch (cod)
                 {
                     case 41:
                        Window vent=new fmrMatricula();
                        vent.show();
                        break;
                     case 42:
                        ventana.getTabSet().addTab(ActualizaDatos.getTabInstance());
                        ventana.getTabSet().selectTab(ventana.getTabSet().getNumTabs()-1);
                        break;
                }
            }
        });
        
        employeeTreeGrid.getData().openAll();

        Principal.addMember(employeeTreeGrid);
    }

    public static class EmployeeTreeNode extends TreeNode {
        public EmployeeTreeNode(String employeeId, String reportsTo, String name) {
            setAttribute("antID", employeeId);
            setAttribute("ID", reportsTo);
            setAttribute("Name", name);
        }
    }

}